
//
//  SCHomeTableViewCell.swift
//  weibo
//
//  Created by 阿城 on 15/12/9.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit
import SnapKit

class SCHomeTableViewCell: UITableViewCell {
    
    var toolBarconstraint:Constraint?
    
    var statusViewModel: SCStatusViewModel?{
        didSet{
            originalView.statusViewModel = statusViewModel
            retweetView.statusViewModel = statusViewModel
            toolBarView.statusViewModel = statusViewModel
            
            
            //判断是否存在转发微博
            if statusViewModel?.statusMod?.retweeted_status == nil{
                
                retweetView.hidden = true
                toolBarconstraint?.uninstall()
                toolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    toolBarconstraint = make.top.equalTo(originalView.snp_bottom).constraint
                })
                
            }else{
                
                retweetView.hidden = false
                toolBarconstraint?.uninstall()
                toolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    toolBarconstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                
            }
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    private func setupUI(){
        
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(toolBarView)
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(kMargin)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
        }
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            
        }
        toolBarView.snp_makeConstraints { (make) -> Void in
            toolBarconstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            make.height.equalTo(40)
            make.bottom.equalTo(contentView)
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
        }
        
    }
    
    private lazy var originalView: SCOriginalView = SCOriginalView()
    private lazy var retweetView: SCRetweetView = SCRetweetView()
    private lazy var toolBarView: SCToolBar = SCToolBar()
    
}
